<?php

$today = $_GET['today'];
$openid = $_GET['openid'];
$conn = mysqli_connect("localhost", "root", "", "cloudwarehouse");

if (!$conn)
    echo "数据库连接失败！";
else {
    $profit = array(5);
    for ($i = 0; $i < 5; $i ++) {

        $beginweek = date("Y-m-d", mktime(0, 0, 0, date("m"), date("d") - date("w") + (1 - $i * 7), date("Y")));
        $endweek = date("Y-m-d", mktime(23, 59, 59, date("m"), date("d") - date("w") + (7 - $i * 7), date("Y")));

        $sql_today = "SELECT sum(profit) FROM commodity_profit WHERE outboundDate BETWEEN '$beginweek' AND '$endweek' AND openid = '$openid'";
        $result_gettoday = mysqli_query($conn, $sql_today);
        $profit_todaypre = mysqli_fetch_array($result_gettoday);
                                                                        //今天利润
        if ($profit_todaypre[0] == NULL) {
            $profit[$i] = 0;
        } else {
            $profit[$i] = round($profit_todaypre[0], 2);
        }


        // $beginweek = date("Y-m-d", mktime(0, 0, 0, date("m"), date("d") - date("w") + 1, date("Y")));      //本周开始时间
        // $endweek = date("Y-m-d", mktime(23, 59, 59, date("m"), date("d") - date("w") + 7, date("Y")));        // 本周结束时间

        // $s1 = date("Y-m-d", mktime(0, 0, 0, date("m"), date("d") - date("w") - 6, date("Y")));
        // $s2 =  date("Y-m-d", mktime(23, 59, 59, date("m"), date("d") - date("w"), date("Y")));
        
    }
    echo json_encode($profit);
}
